package com.leyou.order.interceptor;

import com.leyou.common.constants.MQConstants;
import com.leyou.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 商品上下架消息监听
 */
@Component
@Slf4j
public class SeckillItemListener {
    @Autowired
    private OrderService orderService;

    /**
     * 监听上架消息
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MQConstants.Queue.SECKILL_VERIFY_CODE_QUEUE),
            exchange = @Exchange(name = MQConstants.Exchange.SECKILL_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.SECKILL_ORDER_KEY
    ))
    public void createStaticPage(Map<String,String> seckillMap){

        orderService.buildSeckillOrder(seckillMap);

        log.info("【秒杀商品】秒杀信息，商品抢购成功");
    }


}
